home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / complex.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  3.7 KB  |  122 lines

  1. #ifndef __COMPLEX_CC
  2. #define __COMPLEX_CC
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * complex - Declaration for the Standard Library complex class
  8.  *
  9.  * $Id: complex.cc,v 1.3 1996/09/24 19:16:52 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  * 
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #include <stdcomp.h>
  46.  
  47. #ifndef _RWSTD_NO_NAMESPACE 
  48. namespace std {
  49. #endif
  50.  
  51. template <class T>
  52. complex<T> log10 (const complex<T>& a)
  53. {
  54. #ifndef _RWSTD_MULTI_THREAD
  55.     static 
  56. #endif
  57.     const T log10e = _RWSTD_C_SCOPE_LOG10(_RWSTD_C_SCOPE_EXP(T(1)));
  58.     return log10e * log(a);
  59. }
  60.  
  61. #ifdef _RW_STD_IOSTREAM
  62. template <class T,class charT, class traits>
  63. basic_istream<charT, traits >&  
  64. _RWSTDExportTemplate operator>> (basic_istream<charT, traits >& is,complex<T>& x)
  65. #else
  66. template <class T>
  67. istream& _RWSTDExportTemplate operator>> (istream& is, complex<T>& x)
  68. #endif
  69. {
  70.     //
  71.     // operator >> reads a complex number x in the form
  72.     // u
  73.     // (u)
  74.     // (u, v)
  75.     //
  76.     T u = 0, v = 0;
  77.     char c;
  78.  
  79.     is >> c;
  80.     if (c == '(')
  81.     {
  82.         is >> u >> c;
  83.         if (c == ',') { is >> v  >> c;}
  84.         if (c != ')' )
  85.         {
  86. #ifdef _RW_STD_IOSTREAM
  87.             is.setstate(ios::failbit);
  88. #else
  89.             is.clear(ios::failbit);
  90. #endif
  91.         }
  92.     } 
  93.     else
  94.     {
  95.         is.putback(c);
  96.         is >> u;
  97.     }
  98.  
  99.     if (is)
  100.         x = complex<T>(u,v);
  101.  
  102.     return is;
  103. }
  104.  
  105. #ifdef _RW_STD_IOSTREAM
  106. template <class T,class charT,class traits>
  107. basic_ostream<charT,traits >& _RWSTDExportTemplate operator<< (basic_ostream<charT, traits >& os,const complex<T>& x)
  108. #else
  109. template <class T>
  110. ostream& _RWSTDExportTemplate operator<< (ostream& os, const complex<T>& x)
  111. #endif
  112. {
  113.     return os << "(" << x.real() << "," << x.imag() << ")";
  114. }
  115.  
  116. #ifndef _RWSTD_NO_NAMESPACE
  117. }
  118. #endif
  119.  
  120. #pragma option pop
  121. #endif /* __COMPLEX_CC */
  122.